import java.util.Random;

public class Tool {
    private Tool(){}

    public static void information(Organism organism)//生成信息并展示
    {
        organism.setname(makename(organism));//生成名字
        organism.setspecies(makespecies(organism));//检测物种
        organism.setage(makeage());//随机年龄
        organism.show();
        if(organism instanceof Cat cat)
        {
            cat.voice();
        }
        else if(organism instanceof Dog dog)
        {
            dog.voice();
        }
    }

    public static String makename(Organism organism)//生成名字
    {
        Random r = new Random();
        String[] catname = {"花花","小白","饺子","老大","特洛夫斯基","淑女","苹果派"};
        String[] dogname = {"旺财","铁柱","猛子","疤哥","提洛夫斯基","小黑","伏特加"};
        switch (choose(organism)) {
            case "Cat":
            return catname[r.nextInt(catname.length)];
            case "Dog":
            return dogname[r.nextInt(dogname.length)];
            default:
            return "未知";
        }
    }

    public static String makespecies(Organism organism)//检测物种
    {
        switch (choose(organism)) {
            case "Cat":
            return "猫";
            case "Dog":
            return "狗";
            default:
            return "未知";
        }
    }

    public static int makeage()//随机年龄
    {
        Random r = new Random();
        return r.nextInt(18) + 1;//1 ~ 18
    }

    public static String choose(Organism organism)//判断类
    {
        if(organism instanceof Cat)
        {
            return "Cat";
        }
        else if(organism instanceof Dog)
        {
            return "Dog";
        }
        else
        {
            return "...";
        }
    }
}
